{{#
  var $db = await db('chapter_content');
  let $chapter = {};
  if(KUO.PATH[0] && KUO.PATH[0] != "" && KUO.PATH[0] > 0){
    $chapter = await $db.Where({off:1,id:KUO.PATH[0]}).Order("sortsize asc,id asc").Find();

  }else{
    $chapter = await $db.Where({contentid:KUO.$DATA['id'],off:1}).Order("sortsize asc,id asc").Find();
  }
 
  if(!$chapter){
    
}}
{{ await Mode("TPL").Render("@"+KUO.CLASS+"/"+TPLtemp+"/404",KUO,THIS) }}
{{#
 
}else{ 

  KUO.WZ_title =  $chapter['name']+'_'+KUO.$DATA['name'];
  if( $chapter['describes'] && $chapter['describes'] != "" ){
    KUO.WZ_description = $chapter['describes'];
  }

}}
<html>
<head>
    <meta charset="utf-8">
    <title>{{ KUO.WZ_title }}</title>
    <meta name="description" content="{{ KUO.WZ_description }}" /> 
    <meta name="keywords" content="{{ KUO.WZ_keywords }}" />
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <link rel="shortcut icon" href="{{CDNHOST}}favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="{{CDNHOST}}Tpl/layui/css/layui.css"> 
    <link rel="stylesheet" href="{{CDNHOST}}Tpl/cms/manhua/style.css?a=bb343">
    {{THIS.$WANGZHAN['remarks']}}
    <style>
      body{background:#2b2b2c;color:#999;}.kuohead{background: #242426;}a{color:#999;}
      .chapterneirong .text{background:#2b2b2c;color:#999;}
      .kuofooter{ display:none;}
  
      </style>
    </head>
<body> 

  <div class="kuohead box-shadow padding10" style="position:fixed;top:0;width:100%;">
    <div class="layui-left kuologo layui-hide-xs paddingleft">
      <a href="{{WZHOST}}"><img src="{{pichttp(THIS.$WANGZHAN['photo'])}}"></img></a>
    </div>
  
    <ul class="layui-right  paddingright">
      {{# 
        let $我的 =  await THIS.TYPE_find({id:THIS.$features.configure['我的id'][0]?THIS.$features.configure['我的id'][0]:1 });
        let $下载 =  await THIS.TYPE_find({id:THIS.$features.configure['下载id'][0]?THIS.$features.configure['下载id'][0]:1 });
    
     if($下载){ }}
      <li class="kuo-usernav layui-hide-xs">
          <a href="{{ KuoLink([ KUO.CLASS,$下载.url]) }}">
              <i class="layui-icon layui-icon-cellphone"></i>
              <p>{{$下载.name}}</p>
          </a>
      </li>
    {{# } if($我的){ }}
        
        
      <li class="kuo-usernav layui-hide-xs">
          <a href="{{ KuoLink([ KUO.CLASS,$我的.url]) }}">
              <i class="layui-icon layui-icon-user"></i>
              <p>{{$我的.name}}</p>
          </a>
      </li>
      {{# } }}

      <li class="kuo-usernav " onclick="fanhui();">
        <i class="layui-icon layui-icon-help" ></i>
        <p>反馈</p>
      </li>
      <li class="kuo-usernav" onclick="dengkai(false);">
       
           <i class="layui-icon layui-icon-light" ></i>
           <p id="qiedeng"> 开灯</p>
         
      </li>
  </ul>
  <div class="zhongjiande">  
    <a href="{{WZHOST}}" class="layui-hide-xs">首页</a>
    <span class="layui-hide-xs" > > </span>
    <a href="{{ KuoLink([ KUO.CLASS, KUO.$DATA['url']]) }}" class="crumb__title j-comic-title"> {{KUO.$DATA['name']}} </a>
    <span class="layui-hide-xs" > > </span>
    <h1 class="layui-hide-xs">{{$chapter['name']}}</h1>
  </div>
  <div class="layui-clear"></div>
</div>


<div class="chapterneirong">

  <div id="zhongneirong">
    {{#
      if( $chapter.money == 0 && $chapter.timemoney == 0 ){

        if( ($chapter['content'].indexOf("://")> -1 || 
          $chapter['content'].indexOf("attachment")> -1) 
          && $chapter['content'].indexOf('<video')<= -1 ){

          let shuju_ = explode(',',$chapter['content']);
          for(var mm in shuju_){
    }}
        <img class="lazy-read" src="{{CDNHOST}}Tpl/cms/manhua/image/loadimg.png" lay-src="{{pichttp(shuju_[mm])}}"   >
    {{#
              
          }
        }else{
    }}
      <div class="text">
        {{$chapter['content']}}
      </div>
    {{#
    }
      }else{
    }}
    <div class="text">
      付费查看《{{KUO.$DATA['name']}}》 ({{$chapter['name']}})<br /><br />
      {{$chapter['describes'] !=''?$chapter['describes']+'<br /><br />':''}}
      {{$chapter.vip >0 ?"vip 免费查看<br /><br />":""}}
      {{$chapter.money >0 ?"支付( "+$chapter.money+" )点永久看<br /><br />":""}}
      {{$chapter.timemoney >0 ?"支付( "+$chapter.timemoney+" )点看7天":""}}
    </div>
    {{# } }}  
  </div>
  <div class="layui-clear"></div>
  {{#

    let xiayihua = await $db.ZhiCha("id").Where({off:1,contentid:KUO.$DATA['id'],"id >":$chapter['id'] }).Order("sortsize asc,id asc").Find();
    if(xiayihua){

  }}
  <a class="btn-next-chapter" href="{{ KuoLink([ KUO.CLASS, KUO.$DATA['url'],xiayihua.id]) }}">
    下一话 <i class="layui-icon layui-icon-next"></i>
  </a>
  {{# } }}

  <a class="btn-next-chapter" style="background: #ffd421;color: #6a2501;" id="shoucangx" onclick="shoucang()"> 
    <i class="layui-icon layui-icon-star"></i> 收藏
  </a>
  {{#

    let shangyihua = await $db.ZhiCha("id").Where({off:1,contentid:KUO.$DATA['id'],"id <":$chapter['id'] }).Order("sortsize desc,id desc").Find();
    if(shangyihua){

  }}
  <a class="btn-next-chapter" href="{{ KuoLink([ KUO.CLASS, KUO.$DATA['url'],shangyihua.id]) }}" style="background: #009688;">
    <i class="layui-icon layui-icon-prev"></i> 上一话
  </a>
  {{# } }}

</div>
{{ await Mode("TPL").Render("@"+KUO.CLASS+"/"+TPLtemp+"/foot",KUO,THIS) }}
<script>
var height = 0;
var kaideng = localStorage.getItem("DENGGUANG");
if(!kaideng){
  kaideng =1;
}
var MOURL = "{{ KuoLink([ KUO.CLASS, KUO.$DATA['url']]) }}";
var ID = "{{KUO.$DATA['id']}}";
var NAME = "{{KUO.$DATA['name']}}";
var CHAPTER = "{{$chapter['name']}}";
var JINE= 0;

var CHAPID = "{{$chapter['id']}}";
var GOUMAI = {jine:'{{$chapter.money}}',timejine:'{{$chapter.timemoney}}',vip:'{{$chapter.vip}}'};
function fanhui(){
  layer.confirm("<div style='text-align:center;font-size:20px;color:#000;'>请选择反馈的类型</div>", {
    title:false,
    fixed:false,
    closeBtn:1,
    offset:'200px',
    shadeClose:true,
    btn: ['侵权提醒', '色情低俗', '内容错误']
    ,btn3: function(index, layero){

      apptongxin("chapter/report",{id:ID,cid:CHAPID,type:0},function(data){
					
				layer.msg("感谢您的反馈!",{offset:'200px'});
					
			});
      
    }
  },function(index, layero){
    layer.close(index);
    apptongxin("chapter/report",{id:ID,cid:CHAPID,type:2},function(data){
			layer.msg("感谢您的反馈!",{offset:'200px'});
		});
  }, function(index){
    apptongxin("chapter/report",{id:ID,cid:CHAPID,type:1},function(data){
				layer.msg("感谢您的反馈!",{offset:'200px'});
		});
  });
}  
function allpay(ll){
  if(UID < 1){
    login(allpay,ll);
    return ;
  }
  apptongxin("chapter/buy",{contentid:ID,chapterid:CHAPID,auto:ll},function(data){

    if(data.code == 1 ){
      layer.closeAll();
      layer.msg("购买成功");
      GetDATA();
    }else if(data.code == 2 ){
      pay();
    }

  });
 
}
function GoBuy(){
  var html = `<div style="padding:20px;text-align:center;" class="layui-form" >`;
    if(GOUMAI.vip > 0){
      html+=`<p style="margin-bottom:3px;font-size:14px;color:Red;">购买Vip免费阅读</p>`;
    }
    html+=`<p style="font-size:14px;color:#000;">(`+CHAPTER+`)</p>`;
    html+=`<p style="font-size:14px;text-align:right;padding:10px 0;color:red;"> 剩余:`+JINE+`</p>`;
   
    html+=`<div class="anniuzu" style="padding:10px 0;">`;
    if(GOUMAI.jine > 0){
      html+= `<button type="button" class="layui-btn" style="color:#fff;background:#EC008C;font-size:12px;" onclick="allpay(1);">支付(`+GOUMAI.jine+`)点永久看</button>`; 
    }
    if(GOUMAI.timejine > 0){
      html+= `<button type="button" class="layui-btn" style="color:#fff;background:#F37B1D;font-size:12px;" onclick="allpay(2);">支付(`+GOUMAI.timejine+`)点看7天</button>`; 
    }

   

    html += `</div>`;
    html += `</div>`;
  layer.open({
    type: 1,
    skin: 'layui-layer-demox', 
    closeBtn: 1,
    width:300,
    offset:'200px',
    move:false,
    title:"购买《 "+NAME+" 》",
    anim: 2,
    shadeClose: false, 
    content: html,
    success: function(layero, index){
      layui.form.render();
  },
    cancel: function(index, layero){
      window.location.href = MOURL;
      return false;
    }
  });

}
function shoucang(){
  if(UID < 1 ){
    login(shoucang);
    return ;
  }
    apptongxin("chapter/collect",{id:ID},function(data){
        if(data.code == 1){
            if(typeof(data.data.collect) != "undefined"){
                if(data.data.collect == 1){
                    $("#shoucangx").html('<i class="layui-icon layui-icon-star-fill" ></i> 收藏'); 
                }else{
                    $("#shoucangx").html('<i class="layui-icon layui-icon-star" ></i> 收藏'); 
                }
            }
        }
    });
}
function dengkai(bubian){

  if(kaideng == 1){
    
    if(!bubian){
      kaideng = 2;
      localStorage.setItem("DENGGUANG","2");
      $("style").html('.kuofooter{ display:none;}');
      $("#qiedeng").html("关灯");
    }else{
      $("style").html('body{background:#2b2b2c;color:#999;}.kuohead{background: #242426;}a{color:#999;}.chapterneirong .text{background:#2b2b2c;color:#999;}.kuofooter{ display:none;}');
      $("#qiedeng").html("开灯");
    }
   
  }else{
    if(!bubian){
      kaideng = 1;
      localStorage.setItem("DENGGUANG","1");
      $("style").html('body{background:#2b2b2c;color:#999;}.kuohead{background: #242426;}a{color:#999;}.chapterneirong .text{background:#2b2b2c;color:#999;}.kuofooter{ display:none;}');
      $("#qiedeng").html("开灯");
    }else{
      $("style").html('.kuofooter{ display:none;}');
      $("#qiedeng").html("关灯");
    }
  }
}

function GetDATA(){
  apptongxin("chapter/content",{contentid:ID,chapterid:CHAPID},function(data){
              GOUMAI.jine = data.data.money;
              GOUMAI.timejine = data.data.timemoney;
              if(GOUMAI.jine > 0 || GOUMAI.timejine > 0){
                GoBuy();
              }else{
                if(data.data.content && data.data.content != ""){
                  $("#zhongneirong").html('<div class="text">'+data.data.content +'</div>');
                }else if(data.data.list && data.data.list.length > 0){
                  var zuhehtml = "";
                  for(var xx in data.data.list ){
                    zuhehtml+= `<img class="lazy-read" src="{{CDNHOST}}Tpl/cms/manhua/image/loadimg.png" lay-src="`+data.data.list[xx]+`"   >`;
                  }
                  $("#zhongneirong").html(zuhehtml);
                  layui.flow.lazyimg(); 
                }
              }
          });
}
$(function(){


  layui.flow.lazyimg();
  apptongxin("cms/json/getuid",{},function(data){
    if(data && data.code ==1){
      if(data.data.id){
        JINE = data.data.money;
        UID = data.data.id;
        if(GOUMAI.jine > 0 || GOUMAI.timejine > 0){
           GetDATA();
        }
      }
    }else{
      if(GOUMAI.jine > 0 || GOUMAI.timejine > 0){
        login(GoBuy);
      }
    }
	});
  dengkai(true);
  apptongxin("chapter/getcollect",{id:ID,cid:CHAPID},function(data){
      if(data.code == 1 && data.data){
          if( data.data.collect == 1){
              $("#shoucangx").html('<i class="layui-icon layui-icon-star-fill" ></i> 收藏'); 
          }
      }
  });
});
</script>
{{#  } }}